home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Languages / UCB Logo 3.0 ƒ / sources / MiniEdit Folder / mini.print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-09  |  2.8 KB  |  143 lines  |  [TEXT/ttxt]

  1. /*********************************************************************
  2.  
  3.     mini.print.c
  4.     
  5.     printing functions for Miniedit
  6.     
  7. *********************************************************************/
  8. /*
  9. #include <MacTypes.h>
  10. #include <QuickDraw.h>
  11. #include <PrintTraps.h>
  12. */
  13.  
  14.  
  15. #include <PrintTraps.h>
  16.  
  17. #define topMargin 20
  18. #define leftMargin 20
  19. #define bottomMargin 20
  20.  
  21. #define NIL 0L
  22.  
  23. static    THPrint    hPrint = NIL;
  24. static    int        tabWidth;
  25.  
  26. CheckPrintHandle()
  27. {
  28.     if (hPrint==NIL) 
  29.         PrintDefault(hPrint = (TPrint **) NewHandle( sizeof( TPrint )));
  30. }
  31.  
  32. DoPageSetUp()
  33. {
  34.     PrOpen();
  35.     CheckPrintHandle();
  36.     if (PrStlDialog(hPrint)) ;
  37.     PrClose();
  38. }
  39.  
  40. #define tabChar    ((char)'\t')
  41.  
  42. MyDrawText(p, count)
  43. char    *p;
  44. int        count;
  45. {
  46.     register char    *p1, *p2;
  47.     int                len;
  48.     Point            pt;
  49.  
  50.     p1 = p;
  51.     p2 = p+count;
  52.     while (p<p2) {
  53.         while ((p1<p2) && (*p1 !=tabChar)) *p1++;
  54.         if ((len=p1-p)>0) DrawText( p, 0, p1-p );
  55.         if (*p1==tabChar) {
  56.             GetPen(&pt);
  57.             Move((tabWidth-(pt.h-leftMargin)%tabWidth), 0);
  58.             *p1++;
  59.         }
  60.         p = p1;
  61.     }
  62. }
  63.  
  64. PrDoc(hText, count, hPrint, font, size)
  65. char        **hText;
  66. long        count;
  67. THPrint     hPrint;
  68. int            font;
  69. int            size;
  70. {
  71.     register int     line = 0;
  72.     register int     lastLineOnPage = 0;
  73.     int                length;
  74.     Rect             printRect;
  75.     int             linesPerPage;
  76.     int             lineBase;
  77.     int             lineHeight;
  78.     register char     *ptr, *p1;
  79.     FontInfo        info;
  80.     TPPrPort        printPort;
  81.  
  82.     printPort = PrOpenDoc( hPrint, 0L, 0L );
  83.     SetPort(printPort);
  84.     TextFont(font);
  85.     TextSize(size);
  86.     printRect = (**hPrint).prInfo.rPage;
  87.     GetFontInfo( &info );
  88.     lineHeight = info.leading+info.ascent+info.descent;
  89.     linesPerPage = 
  90.         (printRect.bottom-printRect.top-topMargin-bottomMargin)/lineHeight;
  91.     HLock(hText);
  92.     ptr = p1 = (*hText);
  93.     do {
  94.         PrOpenPage( printPort, 0L );
  95.         lastLineOnPage += linesPerPage;
  96.         MoveTo( printRect.left+leftMargin, 
  97.             (lineBase = printRect.top+lineHeight) );
  98.         do {
  99.             /* PrintLine: */
  100.             while ((ptr<=(*hText)+count) && (*ptr++ != (char)'\r')) ;
  101.             if ((length=(int)(ptr-p1)-1)>0) MyDrawText(p1, length);
  102.             MoveTo( printRect.left+leftMargin, (lineBase += lineHeight));
  103.             p1 = ptr;
  104.         } while ((++line != lastLineOnPage) && (ptr<(*hText)+count));
  105.         PrClosePage( printPort );
  106.     } while (ptr<(*hText)+count);
  107.     HUnlock(hText);
  108.     PrCloseDoc( printPort );
  109. }
  110.  
  111. PrintText(hText, length, gp, tabPixels)
  112. char    **hText;
  113. long    length;
  114. GrafPtr    gp;
  115. int        tabPixels;
  116. {
  117.     TPPrPort    printPort;
  118.     GrafPtr        savePort;
  119.     TPrStatus    prStatus;
  120.     int            copies;
  121.     
  122.     PrOpen();
  123.     CheckPrintHandle();
  124.     tabWidth = tabPixels;
  125.     InitCursor(); /* SetCursor( &arrow ); */
  126.     if (PrJobDialog(hPrint) != 0) {
  127.         PleaseWait();
  128.         GetPort(&savePort);
  129.         for (copies=HowMany(); copies>0; copies--) {
  130.             PrDoc (hText, length, hPrint, (*gp).txFont, (*gp).txSize);
  131.             PrPicFile( hPrint, 0L, 0L, 0L, &prStatus );
  132.         }
  133.         SetPort(savePort);
  134.     }
  135.     PrClose();
  136. }
  137.  
  138. HowMany()
  139. {
  140.     return( ((**hPrint).prJob.bJDocLoop==bDraftLoop) ? 
  141.                 (**hPrint).prJob.iCopies : 1 );
  142. }
  143.